package com.auto.finance.auth.collect.support;

import com.auto.finance.auth.collect.annotations.ApiInclude;
import com.auto.finance.auth.collect.beans.ApiInfo;
import com.auto.finance.auth.collect.support.handles.*;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author tianye
 */
public class RequestPathHandleAdapter {

    private List<RequestPathHandle> handles = new ArrayList<>();

    public RequestPathHandleAdapter() {
        handles.add(new RequestMappingPathHandle());
        handles.add(new GetMappingPathHandle());
        handles.add(new PostMappingPathHandle());
        handles.add(new PutMappingPathHandle());
        handles.add(new DeleteMappingPathHandle());
        handles.add(new PatchMappingPathHandle());
    }

    public List<ApiInfo> handle(String[] prefix, Annotation requestMethod, ApiInclude apiInclude) {
        for (RequestPathHandle handle : handles) {
            if (handle.support(requestMethod)) {
                return handle.handle(prefix, requestMethod, apiInclude);
            }
        }
        return Collections.emptyList();
    }
}
